package com.gz.moreaseManager.sys.controller;

import com.alibaba.fastjson.JSONObject;
import com.gz.moreaseManager.utils.KitFileUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @文件名: UploadController
 * @版权:Copyright 2018-2020版权所有：ganz
 * @描述: 上传文件接口
 * @修改人: ganzheng
 * @修改时间: 9:47
 * @修改内容:新增
 */
@RestController
@RequestMapping("upload")
public class UploadController {

    @RequestMapping(value = "/uploadFiles",method = RequestMethod.POST)
    @ResponseBody
    public Object uploadVideo(@RequestParam("layuiFiles") MultipartFile[] layuiFile, HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> map=new HashMap<>();
        Map<String,Object> map2=new HashMap<>();
        KitFileUtil kitFileUtil=new KitFileUtil();
        map = kitFileUtil.kitFileUtil(layuiFile, request, response);
        String error = map.get("error").toString();
        if("101".equals(error)){
            map2.put("error",101);
            map2.put("message",map.get("message"));
            return map;
        }
        map2.put("error",0);
        String url[]=(String[])map.get("url");
        map2.put("url",url[0]);
        return JSONObject.toJSON(map2);
    }
}
